package worklog.dto;

import java.sql.ResultSet;
import java.sql.SQLException;
import com.google.gson.Gson;

public class EntryDTO {
	private int id;
	private int projectId;
	private int userId;
	private String userName;
	private int type;
	private String projectName;
	private String description;
	private String day;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	public int getProjectId() {
		return projectId;
	}
	public void setProjectId(int projectId) {
		this.projectId = projectId;
	}
	
	public String getProjectName() {
		return projectName;
	}
	public void setProjectName(String projectName) {
		if (projectName == null) this.projectName = "";
		else this.projectName = projectName;
	}

	public int getUserId() {
		return userId;
	}
	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		if (userName == null) this.userName = "";
		else this.userName = userName;
	}
	
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	public String getDay() {
		return day;
	}
	public void setDay(String day) {
		this.day = day;
	}
	

	
	public void set(ResultSet res) {
		try { setId(res.getInt("id")); } catch (SQLException e) { setId(0); }
		try { setProjectId(res.getInt("projectID")); } catch (SQLException e) { setProjectId(0); }
		try { setProjectName(res.getString("projectName")); } catch (SQLException e) { setProjectName(""); }
		try { setType(res.getInt("type")); } catch (SQLException e) { setType(0); }
		try { setUserId(res.getInt("userID")); } catch (SQLException e) { } 
		try { setUserName(res.getString("userName")); } catch (SQLException e) { } 
		try { setDay(res.getString("day")); } catch (SQLException e) { setDay(""); }
		try { setDescription(res.getString("description")); } catch (SQLException e) { setDescription(""); }		
	}
	
	@Override
	public String toString(){
		return new Gson().toJson(this);
	}
}
